<style lang="less">
  @import './login.less';
</style>

<template>
  <div class="login">

    <div class="login-con">
      <div class="login_title">
      管理系统
      </div>
      <div class="form-con">
        <login-form @on-success-valid="handleSubmit"></login-form>
      </div>
    </div>
  </div>
</template>

<script>
import LoginForm from '@/components/login-form'
import { mapGetters, mapActions } from 'vuex'
import { setToken } from '@/libs/util'

export default {
  components: {
    LoginForm
  },
  data: function() {
    return {
      submitFlag: false,
    };
  },
  methods: {
    ...mapActions([
      'handleLogin',
      'getUserInfo',
    ]),
    handleSubmit ({ userName, password }) {
      if (this.submitFlag) return;
      this.submitFlag = true;
      let data = {
        user_name: userName,
        password: password
      }
      this.$Loading.start()
      this.$http.login(data).then((res) => {
        if(res.code==200){
          this.$localStore.set('token', res)
          location.reload()

        }

        // this.submitFlag = false;
        // this.$Loading.finish()
        // if (res.login_statu == 1) {
        //   setToken(res.token)
        //   this.$localStore.set('login_uid', res.login_uid)
        //   this.$localStore.set('login_username', res.login_username)
        //   // this.$router.push('/home');
        //   // 刷新页面
        // } else {
        //   this.$Message.error(res.data.info)
        // }
      }).catch((err) => {
        console.log(err);
        this.submitFlag = false;
        this.$Loading.finish()
      })
    }
  },
  watch: {
  },
}
</script>

<style>

</style>
